package pl;

public class PrimitiveBERTag extends BERTag {

	public PrimitiveBERTag() {
		emptyTag = true;
	}

	public void init(byte[] bArray, short bOff) 
	{
		if ((bArray[bOff] & 0x20) != 0x20)
		{
			 this.tagPC = BER_TAG_TYPE_PRIMITIVE;	
			 this.tagClass =  (byte) (((byte) (bArray[bOff] & 0xC0)>> 6) & 0x03);
		}

		if ((bArray[bOff] & 0x1F) == 0x1F)
		{
			 // TAG has 2 bytes
			 this.tagNumber = (byte) (bArray[(short)(bOff + 1)]);
			 this.tagSizeInBytes = 0x02;
		}
		else
		{
			this.tagNumber = (byte) (bArray[bOff] & 0x1F);
			this.tagSizeInBytes = 0x01;
		}

	}

	public void init(byte tagClass, short tagNumber)
	{
		if (tagNumber < 31 ) tagSizeInBytes = 0x01;
		if (tagNumber > 30 && tagNumber < 128) tagSizeInBytes = 0x02;
		else if (tagNumber > 127 && tagNumber < 1024) tagSizeInBytes = 0x03;
		
		this.tagClass = tagClass;
		this.emptyTag = false;
		this.tagNumber = tagNumber;
	}
}
